<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>PBC指标-目的地运营集团数据管理平台</title>
<include file="Include:style" />
<style>
	.folder span{ display: inline-block; margin: 0 40px 0 1px; }
	.w50{ width: 50px; text-align: center; }
</style>
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text">PBC管理 > 指标库</div>
		<if condition="is_permission('PB',NULL,1)">
		<div class="right">
			<a href="javascript:;" class="btn btn-add">添加指标</a>
		</div>
		</if>
	</div>
	<div id="content">
		<div class="classify">
			<ul>
				<li><a href="javascript:;" class="current">指标库</a></li>
				<li><a href="__APP__/Hr/jixiao_pbc_position">职位PBC</a></li>
				<li><a href="__APP__/Hr/jixiao_pbc_user">人员PBC</a></li>
				<li><a href="__APP__/Hr/jixiao_pbc_view">PBC总览</a></li>
			</ul>
		</div>
		<div class="filter">
			<div class="filter-item">
				<div class="filter-title">指标类型：</div>
				<ul class="filter-order">
					<foreach name="cids" item="vo">
					<li <if condition="$cid eq $vo['name1']">class="current"</if>>
						<a href="__APP__/Hr/jixiao_pbc/cid/{$vo['name1']}">{$vo['name2']}</a>
					</li>
					</foreach>
				</ul>
			</div>
		</div>
		<div class="">
			<table class="table table-bordered">
				<tr class="table-header fixed-table-header">
					<td>关键绩效指标（KPI）</td>
					<td>单位</td>
					<td>权重</td>
					<td>考核周期</td>
					<if condition="is_permission('PB',NULL,1)">
					<td>管理 </td>
					</if>
				</tr>
				<if condition="$result eq NULL">
				<tr>
					<td <if condition="is_permission('PB',NULL,1)">colspan="5"<else />colspan="4"</if> class="text-center">暂无相关内容</td>
				</tr>
				</if>
				<foreach name="result" item="vo">
					<tr class="interlaced-color">
						<td>{$vo['name']}</td>
						<td>{$vo['unit']}</td>
						<td>{$vo['weight']}<if condition="$vo['weight'] neq NULL"><if condition="$vo['cid'] neq 5">%<else />分</if></if></td>
						<td>{$vo['cycle']}</td>
						<if condition="is_permission('PB',NULL,1)">
						<td>
							<a href="javascript:;" class="edit mr5" mid="{$vo['id']}" s_cid="{$vo['cid']}" s_name="{$vo['name']}" s_unit="{$vo['unit']}" s_weight="{$vo['weight']}" s_cycle="{$vo['cycle']}"  data-toggle="tooltip" data-placement="left" title="编辑"><i class="glyphicon glyphicon-edit"></i></a>
							<a href="javascript:;" mid="{$vo['id']}" action="delete" data-toggle="tooltip" data-placement="left" title="删除" class="btn-delete"><i class="glyphicon glyphicon-trash"></i></a>
						</td>
						</if>
					</tr>
				</foreach>
			</table>
		</div>
	</div>
</div>
<!--弹框-->
<div class="modal fade" id="edit-modal">
	<div class="modal-dialog w700">
		<div class="modal-content">
			<div class="modal-header">
				<h4></h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body" style="line-height:30px;">
				<table class="table table-bordered">
					<tr>
						<td width="150" class="text-right"><strong><span class="asterisk">*</span>指标类型</strong></td>
						<td>
							<select name="cid" class="form-control classify classify_select" autocomplete="off">
								<option value="-10" selected>请选择</option>
								<foreach name="cids_list" item="vo">
									<option value="{$vo['name1']}">{$vo['name2']}</option>
								</foreach>
							</select>
							<input type="text" name="zb_input" class="form-control select-add-text ml5" style="width:200px" autocomplete="off">
							<span class="error-item">必填项</span>
							<span class="error-item">该指标类型已存在</span>
						</td>
					</tr>
					<tr>
						<td class="text-right"><strong><span class="asterisk">*</span>关键绩效指标（KPI）</strong></td>
						<td>
							<input type="text" name="name" class="form-control select-add-text name" style="width:200px" autocomplete="off">
							<span class="error-item">必填项</span>
						</td>
					</tr>
					<tr>
						<td class="text-right" width="74"><strong>单位</strong></td>
						<td>
							<input type="text" name="unit" class="form-control" autocomplete="off" />
							<span class="error-item">必填项</span>
						</td>
					</tr>
					<tr>
						<td class="text-right" width="74"><strong><span class="asterisk">*</span>权重</strong></td>
						<td>
							<input type="text" name="weight" class="form-control w50 mr10" autocomplete="off" maxlength="3" onKeyUp="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" /><em class="qz_text hide">±5</em><i class="qz_f">%</i>
							<span class="error-item">必填项</span>
						</td>
					</tr>
					<tr>
						<td class="text-right" width="74"><strong><span class="asterisk">*</span>考核周期</strong></td>
						<td>
							<input type="text" name="cycle" class="form-control name" autocomplete="off" />
							<span class="error-item">必填项</span>
						</td>
					</tr>
				</table>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-affirm">确认</button><button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<include file="Include:javascript"/>
<script type="text/javascript">
$(function(){
	$(".classify_select").on('change',function(){
		if($(this).val()==-10){
			$(this).nextAll('input').val('').show();
		}else{
			$(this).nextAll('input').val('').hide();
		}
	});
	//删除
	$(".btn-delete").ajaxModal({"title_text":"确认提示框","body_text":"您确定要删除吗？","url":"__APP__/Hr/jixiao_pbc_ajax","data":{"id":"mid","action":"action"}});

	$(document).on("change","[name='p_id']",function(){
		var val = $(this).val();
		window.location.href="__APP__/Hr/jixiao_pbc_position/p_id/"+val;
	});
	
	//编辑
	$('.edit').click(function(){
		var modal = $("#edit-modal");
		modal.find(".modal-header h4").text("编辑指标");
		modal.modal();
		$('.select-add-text').val('');
		var mid = $(this).attr("mid"),
			cid = $(this).attr('s_cid'),
			name = $(this).attr('s_name'),
			unit = $(this).attr('s_unit'),
			weight = $(this).attr('s_weight'),
			cycle = $(this).attr('s_cycle');
		modal.find(".btn-affirm").attr({"mid":mid});
		modal.find('.select2').remove();
		modal.find("[name='cid']").val(cid).select2().siblings('input').hide();
		modal.find("[name='name']").val(name);
		modal.find("[name='unit']").val(unit);
		modal.find("[name='cycle']").val(cycle);
		modal.find('.btn-affirm').attr('date_type','edit');
		if(cid!=5 && cid!=6){
			modal.find("[name='weight']").show().val(weight);
			modal.find(".qz_f").html("%");
			modal.find(".qz_text").hide();
		}else if(cid==5){
			modal.find("[name='weight']").hide().val(weight);
			modal.find(".qz_f").html("分");
			modal.find(".qz_text").show().html(weight);
		}else if(cid==6){
			modal.find("[name='weight']").hide().val(weight);
			modal.find(".qz_f").html("%");
			modal.find(".qz_text").show().html(weight);
		}
	})

	//添加
	$(".btn-add").on("click",function(){
		var modal = $("#edit-modal");
		modal.find(".modal-header h4").text("添加指标");
		modal.modal();
		$('.select-add-text').val('');
		modal.find('.btn-affirm').attr('date_type','add');
	});
	
	$("[name='cid']").on("change",function(){
		var val = $(this).val();
		$('#edit-modal').find('.error-item').hide();
		if(val==-10){
			$("[name='weight']").val('').show();
			$('.qz_text').hide();
			$('.qz_f').html("%");
		}else{
			if(val==5){
				$("[name='weight']").hide().val('±5');
				$('.qz_text').html('±5').show();
				$('.qz_f').html("分");
			}else if(val==6){
				$("[name='weight']").hide().val('0');
				$('.qz_text').html('0').show();
				$('.qz_f').html("%");
			}else{
				$("[name='weight']").val('').show();
				$('.qz_text').hide();
				$('.qz_f').html("%");
			}
		}
	});

	//确定
	$("#edit-modal").find(".btn-affirm").on("click",function(){
		var tag = true,
			mid = $(this).attr("mid"),
			modal = $("#edit-modal"),
			action = $(this).attr('date_type'),
			cid = $("[name='cid']").val();

		modal.find(".classify_select").each(function(){
			var $this = $(this),
				val = $this.val(),
				text = $this.nextAll(".select-add-text").val();
			if(val==-10 && text==""){
				$this.siblings(".error-item").eq(0).show();
				tag = false;
			}else{
				$this.find("option").each(function(){
					if($(this).text()==text){
						$this.siblings(".error-item").eq(1).show()
						tag = false;
						return false;
					}
				});
			}
		});
		if(cid!=5 && cid!=6){
			modal.find(".name").each(function(){
				var val = $(this).val();
				if(val=="" || /^\s+$/.test(val)){
					$(this).siblings(".error-item").eq(0).show();
					tag = false;
				}
			});
			modal.find("[name='weight']").each(function(){
				var val = $(this).val();
				if(val=="" || /^\s+$/.test(val)){
					$(this).siblings(".error-item").eq(0).show();
					tag = false;
				}
			})
		}else{
			modal.find(".name").each(function(){
				var val = $(this).val();
				if(val=="" || /^\s+$/.test(val)){
					$(this).siblings(".error-item").eq(0).show();
					tag = false;
				}
			});
		}
		
		if(tag){
			var cid = modal.find("[name='cid']").val(),
				name = modal.find("[name='name']").val(),
				unit = modal.find("[name='unit']").val(),
				weight = modal.find("[name='weight']").val(),
				cycle = modal.find("[name='cycle']").val(),
				zb_input = modal.find("[name='zb_input']").val();
			
			modal.hide();
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"action":action,"id":mid,"zb_input":zb_input,"name":name,"cid":cid,"unit":unit,"weight":weight,"cycle":cycle},
				url:"__APP__/Hr/jixiao_pbc_ajax",
				success:function(data){
					success_pop(data.status);
				}
			});
		}
	});

	//隐藏错误提示
	$('.select-add-text').on("focus",function(){
		$(this).nextAll(".error-item").hide();
	});
	$("#edit-modal").find(".classify").on("change",function(){
		$(this).nextAll(".error-item").hide();
	});
	$("#edit-modal").find(".name,.date,[name='weight']").on("focus",function(){
		$(this).nextAll(".error-item").hide();
	});

	//取消
	$("#edit-modal").on('hidden.bs.modal',function(){
		$(this).find(".error-item").hide();
		$(this).find(".name,.date,[name='unit']").val("");
		$(this).find("select").val(-10).select2();
		$(this).find(".btn-affirm").removeAttr("mid");
		$(this).find('.select-add-text').show();
		$(this).find("[name='name']").html('<option value="-10">请选择</option>');
		$(this).find("[name='weight']").val('').show();
		$(this).find(".qz_text").hide();
		$(this).find(".qz_f").html('%');
	});
		
	$(document).on("change","[name='type']",function(){
		var val = $(this).val();
		window.location.href="__APP__/Hr/jixiao_pbc_ajax/id/{$project['id']}/type/"+val;
	});
});
</script>
</body>
</html>